package com.jsbj.user.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jsbj.base.ResultBean;
import com.jsbj.user.entities.SysGroup;
import com.jsbj.user.service.ISysGroupService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 群组表
 前端控制器
 * </p>
 *
 * @author jsbj
 * @since 2023-02-06
 */
@RestController
@RequestMapping("/sys-group")
public class SysGroupController {

    @Autowired
    private ISysGroupService sysGroupService;

    @ApiOperation(value = "根据设备编号查询组织列表")
    @PostMapping("/queryGroupByEquNum")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "equNum", value = "设备编号", required = true)}
    )
    public ResultBean<List<SysGroup>> queryGroupByEquNum(@RequestParam String equNum) {
        return new ResultBean<List<SysGroup>>(sysGroupService.queryGroupByEquNum(equNum));
    }

    @ApiOperation(value = "查询组织列表")
    @PostMapping("/getList")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "page", value = "页码", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageSize", value = "每页条数", required = true)}
    )
    public ResultBean<IPage<SysGroup>> getList(@RequestBody String inParam) {
        return new ResultBean(sysGroupService.getList(inParam));
    }

    @ApiOperation(value = "新增群组")
    @PostMapping("/add")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true)}
    )
    public ResultBean<String> add(@RequestBody SysGroup sysGroup) throws Exception {
        return new ResultBean<String>(sysGroupService.add(sysGroup));
    }

    @ApiOperation(value = "删除群组")
    @PostMapping("/delete")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "id", value = "数据id", required = true)}
    )
    public ResultBean<String> delete(@RequestParam String id) throws Exception {
        return new ResultBean<String>(sysGroupService.delete(id));
    }

    @ApiOperation(value = "修改保存")
    @PostMapping("/update")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true)}
    )
    public ResultBean<String> update(@RequestBody Map<String,Object> param) throws Exception {
        return new ResultBean<String>(sysGroupService.update(param));
    }

}

